import java.util.Date

import mileena.AppAddress
import mileena.AppComment
import mileena.AppEvent
import mileena.AppMessage
import mileena.AppOwner
import mileena.AppPlace
import mileena.AppPlaceAmenity
import mileena.AppReview
import mileena.AppRole
import mileena.AppUser
import mileena.NeighbourhoodType
import mileena.ProvinceType
import mileena.StateType

class BootStrap {

	def init = {  servletContext ->

		AppRole role1 = new AppRole(appRolePopularity:'10.00',
				appRoleAcceptance:'232',
				appRoleUnacceptance:'12' ).save()

		AppRole role2 = new AppRole(appRolePopularity:'6.00',
				appRoleAcceptance:'2',
				appRoleUnacceptance:'1' ).save()

		AppRole role3 = new AppRole(appRolePopularity:'6.00',
				appRoleAcceptance:'222',
				appRoleUnacceptance:'11' ).save()

		AppUser user1 = new AppUser(appRole:role1,appUserFirstName:'Juan',
				appUserMiddleName:'Carlos',
				appUserLastName:'Cancela',
				appUserMail:'cancela.juancarlos@gmail.com',
				appUserSignUp: new Date(),
				appUserPassword:'password',
				appUserDescription:'Im one of the creator of the whole thing!',
				appImage:'http://media.linkedin.com/mpr/mpr/shrink_80_80/p/3/000/01b/121/19dae76.jpg').save()


		AppUser user2 = new AppUser(appRole:role2, appUserFirstName:'Jose',
				appUserMiddleName:'Luis',
				appUserLastName:'Cancela',
				appUserMail:'joseluis.cancela@gmail.com',
				appUserSignUp: new Date(),
				appUserPassword:'password3',
				appUserDescription:'Im ODDA of the creator of the whole thing!',
				appImage:'http://media.linkedin.com/mpr/mpr/shrink_80_80/p/3/000/01b/121/19dae76.jpg').save()


		AppOwner owner1 = new AppOwner(appRole:role3,
				appUserFirstName:'Diego',
				appUserMiddleName:'Aristobulo',
				appUserLastName:'Hansen',
				appUserMail:'diego.hansen@gmail.com',
				appUserSignUp: new Date(),
				appUserPassword:'password2',
				appUserDescription:'Im one of the creator of the whole thing, ALSO!',
				appOwnerPosition:'RRPP').save()


		AppAddress address1 = new AppAddress(appAddressStreetName:'Castor Barrows',
				appAddressStreetNumber:'980',
				appAddressFloor:'8',
				appAddressNeighbourhood:NeighbourhoodType.BOEDO.toString(),
				appAddressProvince:ProvinceType.CAPITAL_FEDERAL.toString(),
				appAddressState:StateType.BUENOS_AIRES.toString(),
				appAddressLatitude:'123.4434',
				appAddressLongitute:'3323.455').save()


		AppReview review1 = new AppReview(appReviewGlobalScore:'8.87',
				appReviewEnjoyability:'4.55',
				appReviewCleanability:'8.95',
				appReviewOrganizational:'6.55',
				appReviewPrice:'3.44',
				appReviewAvailability:'1.22',
				appReviewParking:'3.22',
				appReviewCustomerExperience:'5.44',
				appReviewAccesibility:'4.33').save();


		AppPlaceAmenity amenity1 = new AppPlaceAmenity(appPlaceAmenityTotalSize:'650',
				appPlaceAmenityParking:'400',
				appPlaceAmenityAirConditioner:"true",
				appPlaceAmenitySecutiry:"false").save()


		AppPlace place1 = new AppPlace(appAddress:address1,
				appReview:review1,
				appPlaceAmenity: amenity1,
				appPlaceName:'The Java Coffee',
				appPhone: '1556065555',
				appPlaceSignUp:new Date()).save()
				
				
		user1.addToFavouritePlaces(place1).save()



		AppReview review2 = new AppReview(appReviewGlobalScore:'8.87',
				appReviewEnjoyability:'4.55',
				appReviewCleanability:'8.95',
				appReviewOrganizational:'6.55',
				appReviewPrice:'3.44',
				appReviewAvailability:'1.22',
				appReviewParking:'3.22',
				appReviewCustomerExperience:'5.44',
				appReviewAccesibility:'4.33').save();


		AppPlaceAmenity amenity2 = new AppPlaceAmenity(appPlaceAmenityTotalSize:'650',
				appPlaceAmenityParking:'400',
				appPlaceAmenityAirConditioner:"true",
				appPlaceAmenitySecutiry:"false").save()


		AppPlace place2 = new AppPlace(appAddress:address1,
				appReview:review2,
				appPlaceAmenity: amenity2,
				appPlaceName:'Salome',
				appPhone: '1556065555',
				appPlaceSignUp:new Date()).save()




		AppReview review3 = new AppReview(appReviewGlobalScore:'8.87',
				appReviewEnjoyability:'4.55',
				appReviewCleanability:'8.95',
				appReviewOrganizational:'6.55',
				appReviewPrice:'3.44',
				appReviewAvailability:'1.22',
				appReviewParking:'3.22',
				appReviewCustomerExperience:'5.44',
				appReviewAccesibility:'4.33').save();


		AppPlaceAmenity amenity3 = new AppPlaceAmenity(appPlaceAmenityTotalSize:'650',
				appPlaceAmenityParking:'400',
				appPlaceAmenityAirConditioner:"true",
				appPlaceAmenitySecutiry:"false").save()


		AppPlace place3 = new AppPlace(appAddress:address1,
				appReview:review3,
				appPlaceAmenity: amenity3,
				appPlaceName:'The Java Friends',
				appPhone: '1556065555',
				appPlaceSignUp:new Date()).save()


		AppReview review4 = new AppReview(appReviewGlobalScore:'8.87',
				appReviewEnjoyability:'4.55',
				appReviewCleanability:'8.95',
				appReviewOrganizational:'6.55',
				appReviewPrice:'3.44',
				appReviewAvailability:'1.22',
				appReviewParking:'3.22',
				appReviewCustomerExperience:'5.44',
				appReviewAccesibility:'4.33').save();


		AppPlaceAmenity amenity4 = new AppPlaceAmenity(appPlaceAmenityTotalSize:'650',
				appPlaceAmenityParking:'400',
				appPlaceAmenityAirConditioner:"true",
				appPlaceAmenitySecutiry:"false").save()


		AppPlace place4 = new AppPlace(appAddress:address1,
				appReview:review4,
				appPlaceAmenity: amenity4,
				appPlaceName:'The Java Bar of friends',
				appPhone: '1556065555',
				appPlaceSignUp:new Date()).save()




		AppEvent event1 = new AppEvent(appOwner: owner1,
				appPlace: place1,
				appEventName: 'The Java One party',
				appEventBegin: new Date(),
				appEventEnd: new Date()).save()


		AppComment cmt2 = new AppComment(appOwner: owner1,
				appEvent: event1,
				appCommentText: 'Hello, this is the very first COMMENT on Mileena!' ,
				appCommentDate: new Date() ).save()


		AppComment cmt1 = new AppComment(appEvent: event1,
				appOwner: owner1,
				appCommentText: 'Hello, this is the second COMMENT on Mileena!' ,
				appCommentDate: new Date() ).save()


		AppMessage msg1 = new AppMessage(appEvent: event1,
				appUser: user1,
				appMessageText: 'Hello, this is the first MESSAGE on Mileena!' ,
				appMessageDate: new Date() ).save()


		AppMessage msg2 = new AppMessage(appEvent: event1,
				appUser: user1,
				appMessageText: 'Hello, this is the second MESSAGE on Mileena!' ,
				appMessageDate: new Date() ).save()


		//def user1Msgs1 = AppUser.findByAppUserMail('cancela.juancarlos@gmail.com')
		//user1.addToMessages(msg1)
		//user1.save()
		//def event1Msgs1 = AppEvent.findByAppEventName('The Java One party');
		//event1Msgs1.addToMessages((AppMessage.findAllByAppEvent(event1)))
		//event1Msgs1.addToComments((AppComment.findAll("from AppComment as a where a.appEvent.appEventName=:eventName", [eventName:'The Java One party']))
	}

	def destroy = {
	}
}
